import turtle

from flask import jsonify


def success_api(msg: str = "成功"):
    """ 成功响应 默认值”成功“ """
    return jsonify(success=True, msg=msg)


def fail_api(msg: str = "失败"):
    """ 失败响应 默认值“失败” """
    return jsonify(success=False, msg=msg)


def table_api(msg: str = "", count=0, data=None, limit=10):
    """ 动态表格渲染响应 """
    res = {
        'msg': msg,
        'code': 0,
        'data': data,
        'count': count,
        'limit': limit

    }
    return jsonify(res)


# 卫星用户返回
def wxuser_success_api(errno: int = 0,flagsing:int=-1, user: dict = {},remark_count:int=0, openid: str = '',access_token: str = '', dbusers=None, refresh_token: str = '',token: str = '', msg: str = '成功'):
    res = {
        "errno": errno,

        "data": {"userInfo": user, "token": token, 'openid': openid,
                 'access_token': access_token, 'refresh_token': refresh_token,
                 'dbusers':dbusers,
                 'remark_count':remark_count,
                 },
        'flagsing':flagsing,
        "msg": msg
    }
    return jsonify(res)


# 收货地址
def address_api(errno: int = 0, data:dict=[], msg: str = '成功'):
    res = {
        "errno": errno,
        "data": {'addresslist': data},
        "msg": msg
    }
    return jsonify(res)


# 商品
def goods_api(errno: int = 0, goods=None, classify=None, msg: str = '成功'):
    res = {
        "errno": errno,
        "data": {'menuslist': classify, 'datagoodsliat': goods},
        "msg": msg
    }
    return jsonify(res)


# index商品返回
def index_goods_api(errno: int = 0, goods=None, msg: str = '成功'):
    res = {
        "errno": errno,
        "data": {'goods': goods, },
        "msg": msg
    }
    return jsonify(res)


# catrs

def carts_api(errno: int = 0, subOrders=None, ordercount: dict = {}, msg: str = '成功'):
    res = {
        "errno": errno,
        "data": {'subOrders': subOrders, 'ordercount': ordercount},
        "msg": msg
    }
    return jsonify(res)


# orders
def orders_api(errno: int = 0, order_sn: str = '', good=None, msg: str = '成功', code=''):
    res = {
        "errno": errno,
        "order_sn": order_sn,
        "good": good,
        "msg": msg,
        "code": code
    }
    return jsonify(res)


def orders_out_api(errno: int = 0, orderlist=None, msg: str = '成功'):
    res = {
        "errno": errno,
        "data": {'orderlist': orderlist},
        "msg": msg
    }
    return jsonify(res)


# 优惠卷

def coupon_api(errno: int = 0, usercoupon=None, msg: str = '成功'):
    res = {
        "errno": errno,
        "data": {'usercoupon': usercoupon},
        "msg": msg
    }
    return jsonify(res)


def bandas_api(errno: int = 0, banner=None, msg: str = '成功'):
    res = {
        "errno": errno,
        "data": {'banners': banner},
        "msg": msg
    }
    return jsonify(res)


def stores_api(errno: int = 0, stores=None, msg: str = '成功'):
    res = {
        "errno": errno,
        "data": {'shoplist': stores},
        "msg": msg
    }
    return jsonify(res)


def remark_api(errno: int = 0, remark=None, good=None, msg: str = '成功'):
    res = {
        "errno": errno,
        "data": {'remarklist': remark, 'good': good},
        "msg": msg
    }
    return jsonify(res)
